﻿@model List<RoadQualityEvalAPI.Models.PotholeModel>

@{
    Layout = null;
    var totalPotholes = Model.Count;
}


<script type="text/javascript">

    $('.falsePotholesRemove').on('click', function (evt) {


        evt.preventDefault();
        evt.stopPropagation();

        //alert("Clicked");
        console.log('clicked');
        url = $(this).data('url');

        $.get(url, function (data) {

            alert("All potholes older than 2 weeks and with a certainty index smaller than 3 have been removed!");
            location.reload();

        });

    });

</script>

<h4>Collected potholes statistics (data from Android clients):</h4>
<hr />
<div id="potholes_general_stats">

    <div class="row">
        <p>General information regarding gathered potholes (stats, etc.)</p>
    </div>

    <div class="row">
        @Html.Label("Total potholes: " + totalPotholes)
    </div>


    <div class="row">
        @*
        <button data-url='@Url.Action("RemoveFalsePotholes", "Admin")' class="falsePotholesRemove">Remove false potholes</button>  
        @{
            List<SelectListItem> listItems = new List<SelectListItem>();
            listItems.Add(new SelectListItem
            {
                Text = "Older than 2 weeks",
                Value = "TwoWeeks"
            });
            listItems.Add(new SelectListItem
            {
                Text = "Older than 1 week",
                Value = "OneWeek",
                Selected = true
            });
            listItems.Add(new SelectListItem
            {
                Text = "Older than 3 days",
                Value = "ThreeDays"
            });   
         }

          @Html.DropDownList("selectedPotholes", new SelectList(listItems,"Value","Text"))
        *@

        @using (Html.BeginForm("RemoveFalsePotholes", "Admin"))
        {
            List<SelectListItem> listItems = new List<SelectListItem>();
            listItems.Add(new SelectListItem
            {
                Text = "Older than 2 weeks",
                Value = "TwoWeeks"
            });
            listItems.Add(new SelectListItem
            {
                Text = "Older than 1 week",
                Value = "OneWeek",
                Selected = true
            });
            listItems.Add(new SelectListItem
            {
                Text = "Older than 3 days",
                Value = "ThreeDays"
            });   
            
            <input type="submit" value="Remove False Potholes">
            @Html.DropDownList("selectedPotholes", new SelectList(listItems, "Value", "Text")) 
        }

    </div>

    <div class="row">

        <table class="customTable">
            <tr>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().CreatedAt)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().Description)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().Quality)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().Type)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().Location)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.FirstOrDefault().Username)
                </th>

            </tr>

            @foreach (var pot in Model)
            {
                string baddness = "";
                if (pot.Type == 1)
                {
                    baddness = "Normal pothole";
                }
                else if (pot.Type == 2)
                {
                    baddness = "Bad pothole";
                }
                
                <tr>
                    <td>
                        @Html.DisplayFor(m => pot.CreatedAt)
                    </td>
                    <td>
                        @Html.DisplayFor(m => pot.Description)
                    </td>
                    <td>
                        @Html.DisplayFor(m => pot.Quality)
                    </td>
                    <td>
                        @Html.Raw(baddness)
                    </td>
                    <td>
                        @Html.DisplayFor(m => pot.Location)
                    </td>
                    <td>
                        @Html.DisplayFor(m => pot.Username)
                    </td>

                </tr>
            }

        </table>

    </div>


</div>

